package com.gsn.chooseGame;

import com.badlogic.gdx.Gdx;
import com.gsn.chooseChannel.GiftInitLayer;
import com.gsn.common.PortalCommingLayer;
import com.gsn.common.PortalDialogLayer;
import com.gsn.common.PortalDialogYesNoLayer.EButtonType;
import com.gsn.common.PortalDialogYesNoLayer.EDialogType;
import com.gsn.common.PortalDialogYesNoLayer.IDialogYesNoListener;
import com.gsn.common.PortalHelpLayer;
import com.gsn.dataCommon.ConfigModel;
import com.gsn.dataCommon.UserData;
import com.gsn.engine.myplay.GsnGame;
import com.gsn.engine.myplay.GsnScreen;
import com.gsn.engine.utility.UtilityGettor;

import com.gsn.poker.asset.PortalTexture;
import com.gsn.poker.game.MyPoker;
import com.gsn.poker.packet.PacketFactory;

public class ChooseGameScreen extends GsnScreen implements IDialogYesNoListener {
	private static final String CHANGE_ACOUNT = "changeAcount";
	private static final String DIFFERENT_VERSION = "differentVersion";
	public ChooseGameLayer chooseGameLayer;
	public PortalDialogLayer dialogLayer;
	public PortalCommingLayer commingLayer;
	public PortalHelpLayer helpLayer;
	
	public ChooseGameScreen(float width, float height) {
		super(width, height);
	}

	@Override
	public void onInit() {

		commingLayer = new PortalCommingLayer(width, height);
		addLayer(commingLayer, 1, false);

		helpLayer = new PortalHelpLayer(width, height);
		addLayer(helpLayer, 2, false);

		dialogLayer = new PortalDialogLayer();
		dialogLayer.setDialogListener(ChooseGameScreen.this);
		addLayer(dialogLayer, 3, false);

		chooseGameLayer = new ChooseGameLayer(width, height);
		addLayer(chooseGameLayer, 0, true);

		setDefaultInputListener();
	}

	@Override
	public void setDefaultInputListener() {
		chooseGameLayer.setInputListener();
		// if (ConfigModel.portalJson != null) {
		// try {
		// if
		// (!ConfigModel.portalJson.getString("android_version").equals(ConfigModel.version))
		// {
		// dialogLayer.createDialog(EDialogType.YES, DIFFERENT_VERSION,
		// "Hệ thống myPlay đã sửa đổi, bạn hãy cập nhật phiên bản mới nhất nhé?");
		// dialogLayer.show();
		// }
		// } catch (Exception e) {
		// // TODO: handle exception
		// e.printStackTrace();
		// }
		// }
	}

	@Override
	public void clickButton(String nameDlg, EButtonType btn) {
		// TODO Auto-generated method stub
		switch (btn) {
		case YES:
			if (nameDlg.equals(CHANGE_ACOUNT)) {
				MyPoker.game.setLoginScreen();
			} else if (nameDlg.equals(DIFFERENT_VERSION)) {
				UtilityGettor.inst().endActivity();
				Gdx.app.exit();
			}
			break;

		default:
			break;
		}
	}

	public void showCommingDialog() {
		// TODO Auto-generated method stub
		commingLayer.show();
	}

	public void showHelpDialog() {
		// TODO Auto-generated method stub
		helpLayer.show();
	}

	@Override
	protected void setAssetNeed() {
		// TODO Auto-generated method stub
		addAsset(PortalTexture.inst());
	}

	@Override
	public GsnGame getGame() {
		// TODO Auto-generated method stub
		return MyPoker.game;
	}

	public void showChangeAcount() {
		// TODO Auto-generated method stub
		dialogLayer.createDialog(EDialogType.YES_NO, CHANGE_ACOUNT, "Bạn có muốn đổi sang tài khoản khác không?");
		dialogLayer.show();
	}

	public void setInfoUser() {
		if (chooseGameLayer != null) {
			chooseGameLayer.setInfoUser();
		}
	}

	@Override
	public void onShowScreen() {
		// TODO Auto-generated method stub
		super.onShowScreen();

	}

	public void onBackPress() {
		showChangeAcount();
	}

	public void hideAllLayer() {
		// TODO Auto-generated method stub
		if (dialogLayer != null)
			dialogLayer.hide();

		if (commingLayer != null)
			commingLayer.hide();
		if (helpLayer != null)
			helpLayer.hide();
		
		Gdx.input.setInputProcessor(chooseGameLayer);
	}
}
